#include "stdafx.h"
#include "NetBinder.h"


_NAMESPACE_BEGIN

static void SysAddrGetString(CONST_REF(SystemAddress) sysadd, bool port, std::string& out)
{
	out.clear();
	out = sysadd.ToString(port);
}

Net_ScriptBinder::Net_ScriptBinder()
{
	int r;
	asIScriptEngine* engine=AngelScriptBinder::Instance()->GetEngine();

	///NetId
	r=engine->RegisterEnum("NetId"); assert( r >= 0 );
	r=engine->RegisterEnumValue("NetId","ID_BEGIN_GAME",ID_BEGIN_GAME);

	///SystemAddress
	r = engine->RegisterObjectType("SystemAddress",sizeof(SystemAddress), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C);assert( r >= 0 );
	DECLARE_CONSTRUCTOR(SystemAddress)
	r = engine->RegisterObjectProperty("SystemAddress", "uint16 port",offsetof(SystemAddress,port)); assert( r >= 0 );	

	r = engine->RegisterGlobalFunction
		("void SysAddrGetString(const SystemAddress&in,bool,string&out)",asFUNCTION(SysAddrGetString), asCALL_CDECL);	 assert( r >= 0 );

	///RoomDesc
	r = engine->RegisterObjectType("RoomDesc",sizeof(RoomDesc), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_C);assert( r >= 0 );
	DECLARE_CONSTRUCTOR(RoomDesc)
	r = engine->RegisterObjectProperty("RoomDesc", "string hostName", offsetof(RoomDesc, hostName)); assert( r >= 0 );
	r = engine->RegisterObjectProperty("RoomDesc", "SystemAddress serverAdd",offsetof(RoomDesc,serverAdd)); assert( r >= 0 );	
	r = engine->RegisterObjectProperty("RoomDesc", "string passWord",offsetof(RoomDesc,passWord)); assert( r >= 0 );	

	///NetInterface
	r = engine->RegisterObjectType("NetInterface",sizeof(NetInterface), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(NetInterface)
	TYPEMETHODS(NetInterface)

	///NetClient
	r = engine->RegisterObjectType("NetClient",sizeof(NetClient), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(NetClient)
	TYPEMETHODS(NetClient)
	DECLARE_DERIVE(NetClient,NetInterface)

	///NetServer
	r = engine->RegisterObjectType("NetServer",sizeof(NetServer), asOBJ_REF);	assert( r >= 0 );
	DECLARE_EMPTY_ADD_RELEASE_REF(NetServer)
	TYPEMETHODS(NetServer)
	DECLARE_DERIVE(NetServer,NetInterface)

	///NetManager
	r = engine->RegisterObjectType("NetManager",sizeof(NetManager), asOBJ_REF|asOBJ_NOHANDLE );	assert( r >= 0 );
	TYPEMETHODS(NetManager)
	r = engine->RegisterGlobalProperty("NetManager NetManager_I",NetManager::Instance() );	 assert( r >= 0 );

}

Net_ScriptBinder::~Net_ScriptBinder()
{

}

_NAMESPACE_END

